
<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- head 中 -->
    <link rel="stylesheet" href="css/materialize.min.css">

    <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

    <title>H5 网页示例</title>

    <style>
        #title{
            color: #fb8c00;
        }

    </style>

</head>
<body style="margin-left: 10px;margin-right: 10px">



<iframe src="https://player.bilibili.com/player.html?bvid=BV1AT411j7is&cid=338628383"
        width="560" height="340" frameborder="0" allowfullscreen>
</iframe>

<!--<!DOCTYPE html>
<html>
<head>
    <title>搜索页面</title>

</head>
<body>
<h1>搜索本地html文件</h1>
<div class="search-container">
    <input type="text" id="search-input" placeholder="输入搜索内容">
    <button id="search-btn">搜索</button>
</div>

<ul id="search-results"></ul>

<script>
    const fs = require('fs');
    const path = require('path');

    const searchBtn = document.getElementById('search-btn');
    const searchInput = document.getElementById('search-input');
    const searchResults = document.getElementById('search-results');

    searchBtn.addEventListener('click', () => {
        const searchValue = searchInput.value;
        if (searchValue) {
            // 读取指定目录下所有html文件
            const files = fs.readdirSync('/kotoba').filter((file) => {
                return path.extname(file) === '.html';
            });
            // 定义可以接收搜索结果的数组
            let results = [];
            // 循环读取每个html文件并查找卡片标题
            files.forEach((file) => {
                const content = fs.readFileSync(`/kotoba${file}`, 'utf8');
                const matchResult = content.match(/<h2 class="card-title">(.+)<\/h2>/);
                if (matchResult && matchResult[1].includes(searchValue)) {
                    results.push(file);
                }
            });
            // 在搜索结果的div中显示html文件列表
            if (results.length === 0) {
                searchResults.innerHTML = '<p>未找到匹配的结果</p>';
            } else if (results.length === 1) {
                window.location.href = `/kotoba${results[0]}`;
            } else {
                let ul = '<ul>';
                results.forEach((file) => {
                    ul += `<li><a href="/kotoba${file}">${file}</a></li>`;
                });
                ul += '</ul>';
                searchResults.innerHTML = ul;
            }
        }
    });
</script>

<style>
    .search-container {
        margin-top: 30px;
    }

    #search-input {
        width: 250px;
        padding: 10px;
        font-size: 18px;
        border: 1px solid #ccc;
        border-radius: 4px;
        margin-right: 10px;
    }

    #search-btn {
        padding: 12px;
        font-size: 18px;
        border: none;
        border-radius: 4px;
        cursor: pointer;
        background-color: #4CAF50;
        color: white;
    }

    #search-results {
        margin-top: 20px;
    }
</style>
</body>
</html>-->



<!--<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>翻译搜索器</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.slim.min.js"></script>
    <script src="//fanyi.baidu.com/static/translation/js/bdict.min.js"></script>
    <style>
        .search-container {
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 20px auto;
        }

        #search-input {
            width: 60%;
            height: 30px;
            padding: 5px;
            margin-right: 10px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
        }

        #search-btn {
            padding: 5px 10px;
            border-radius: 5px;
            font-size: 16px;
            color: #ffffff;
            background-color: #0077cc;
            border: none;
            cursor: pointer;
        }

        #search-btn:hover {
            background-color: #005fa3;
        }

    </style>
</head>

<body>
<div class="search-container">
    <input type="text" id="search-input" placeholder="输入要翻译的内容">
    <button id="search-btn">搜索</button>
</div>


<script>
    // 设置最低搜索间隔时间
    var searchInterval = 2000;

    // 当前搜索时间戳
    var currentSearchTime = new Date().getTime();

    // 监听搜索按钮点击事件
    document.getElementById("search-btn").addEventListener("click", function() {
        // 获取搜索内容
        var searchContent = document.getElementById("search-input").value;
        // 检查是否能够执行搜索
        var currentTime = new Date().getTime();
        if (currentTime - currentSearchTime >= searchInterval) {
            // 设置当前搜索时间戳
            currentSearchTime = currentTime;
            // 创建本地html文件的临时链接
            var fileUrl = URL.createObjectURL(new Blob(['<!DOCTYPE html><html><body><h1>翻译结果：</h1></body></html>'], {type: 'text/html'}));
            // 构造百度翻译链接
            var translateUrl = "https://fanyi.baidu.com/#auto/en/" + encodeURI(searchContent);
            // 创建新窗口打开翻译结果
            window.open(translateUrl, '_blank');
            // 打开本地html文件显示翻译结果
            var file = new File(['<!DOCTYPE html><html><body><h1>翻译结果：</h1><p>' + searchContent + '</p></body></html>'], 'translate-result.html', {type: 'text/html'});
            var fileWriter = new FileWriter();
            fileWriter.write(file, fileUrl);
            // 解除本地html链接引用
            URL.revokeObjectURL(fileUrl);
        } else {
            // 显示提示信息
            alert("请稍后再搜索！");
        }
    });

</script>
</body>
</html>-->

<!--<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Search Local Files</title>
    <style>
        body {
            font-family: Arial, sans-serif;
        }

        .wrapper {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 50px;
        }

        h1 {
            margin-bottom: 20px;
        }

        form {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-bottom: 30px;
        }

        label {
            font-weight: bold;
            margin-bottom: 10px;
        }

        #search {
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #ccc;
            font-size: 16px;
            width: 300px;
            margin-right: 10px;
        }

        #search:focus {
            outline: none;
            border: 2px solid #1E90FF;
        }

        input[type="submit"] {
            padding: 10px 20px;
            border-radius: 5px;
            border: none;
            background-color: #1E90FF;
            color: #fff;
            font-size: 16px;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #007FFF;
        }

        .dropdown {
            position: relative;
            display: inline-block;
        }

        .dropdown-content {
            display: none;
            position: absolute;
            z-index: 1;
            background-color: #f9f9f9;
            min-width: 160px;
            box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
            padding: 12px 16px;
            border-radius: 5px;
        }

        .dropdown.show {
            display: block;
        }

        .dropdown-content a {
            color: black;
            padding: 6px 12px;
            text-decoration: none;
            display: block;
        }

        .dropdown-content a:hover {
            background-color: #f1f1f1;
        }

        .dropbtn {
            background-color: #1E90FF;
            color: #fff;
            padding: 10px 20px;
            font-size: 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        .dropbtn:hover, .dropbtn:focus {
            background-color: #007FFF;
        }

        .dropdown:hover .dropdown-content {
            display: block;
        }


    </style>

</head>
<body>
<div class="wrapper">
    <h1>Search Local Files</h1>
    <form>
        <label for="search">Enter keyword to search:</label>
        <input type="search" id="search" placeholder="Type here...">
        <input type="submit" value="Search">
    </form>
    <div class="dropdown" id="dropdown">
        <button class="dropbtn" id="dropbtn">Choose file</button>
        <div class="dropdown-content" id="dropdown-content"></div>
    </div>
</div>
<script>
    const form = document.querySelector('form');
    const search = document.querySelector('#search');
    const dropdown = document.querySelector('#dropdown');
    const dropdownContent = document.querySelector('#dropdown-content');
    const dropbtn = document.querySelector('#dropbtn');

    form.addEventListener('submit', searchFiles);

    let fileNames = [];

    function searchFiles(e) {
        e.preventDefault();
        const searchTerm = search.value.trim().toLowerCase();
        if (!searchTerm) {
            return;
        }
        fileNames = searchInDirectory(searchTerm);
        if (fileNames.length == 0) {
            alert('No matching files found!');
            return;
        }
        if (fileNames.length == 1) {
            location.href = fileNames[0];
            return;
        }
        removeAllChildNodes(dropdownContent);
        fileNames.forEach(addFileNameToDropdown);
        dropdown.classList.add('show');
    }

    function searchInDirectory(keyword) {
        const fileNames = [];
        const dirReader = window.requestFileSystemSync(window.PERSISTENT, 1024*1024);

        function onReadDir(entries) {
            for (let i = 0; i < entries.length; i++) {
                const entry = entries[i];
                if (entry.isDirectory) {
                    const reader = entry.createReader();
                    const subEntries = reader.readEntries();
                    onReadDir(subEntries);
                } else {
                    const extension = entry.name.split('.').pop();
                    if (extension === 'html') {
                        const fileName = entry.name.toLowerCase();
                        if (fileName.includes(keyword)) {
                            const path = entry.fullPath.replace('/index.html', '.html');
                            fileNames.push(path);
                        }
                    }
                }
            }
        }

        const rootEntries = dirReader.root.createReader().readEntries();
        onReadDir(rootEntries);

        return fileNames;
    }

    function removeAllChildNodes(parent) {
        while (parent.firstChild) {
            parent.removeChild(parent.firstChild);
        }
    }

    function addFileNameToDropdown(fileName) {
        const link = document.createElement('a');
        link.href = fileName;
        link.textContent = fileName.replace(/^.*[\\\/]/, '');
        dropdownContent.appendChild(link);
        link.addEventListener('click', (e) => {
            e.preventDefault();
            location.href = e.target.href;
        });
    }

    function hideDropdown(e) {
        dropdown.classList.remove('show');
    }

    document.addEventListener('click', (e) => {
        if (!dropdown.contains(e.target)) {
            dropdown.classList.remove('show');
        }
    });


</script>
</body>
</html>-->




